/*
 * Copyright 2007 Yegor Jbanov
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.spicesoft.clientobjects.samples.form;

import java.util.Date;

import javax.swing.JFrame;

import com.spicesoft.clientobjects.BeanEnhancer;
import com.spicesoft.clientobjects.BeanRegistry;

public class FormSample {

  public static void main(String[] args) {
    // Register POJOs
    BeanRegistry.registerType(Customer.class);
    BeanRegistry.registerType(Address.class);
    
    // Create Customer POJO
    Customer pojo = new Customer();
    pojo.setBirthDate(new Date());
    pojo.setCorporateCustomer(true);
    pojo.setFirstName("Yegor");
    pojo.setLastName("Jbanov");
    
    Address permanentAddress = new Address();
    permanentAddress.setAddressLine1("Saturn Street");
    permanentAddress.setAddressLine2("NW");
    permanentAddress.setCity("LunarCity");
    permanentAddress.setProvince("South Gusev");
    permanentAddress.setCountry("Gusev Federation");
    permanentAddress.setPostalCode("UUYEEY");
    pojo.setPermanentAddress(permanentAddress);
    
    Address mailingAddress = new Address();
    mailingAddress.setAddressLine1("Mars Street");
    mailingAddress.setAddressLine2("");
    mailingAddress.setCity("LunarCity");
    mailingAddress.setProvince("South Gusev");
    mailingAddress.setCountry("Gusev Federation");
    mailingAddress.setPostalCode("YYUIIU");
    pojo.setMailingAddress(mailingAddress);
    
    // Convert POJO to JavaBean (i.e. add property change support)
    Customer bean = BeanEnhancer.addPropertyChangeSupport(pojo);

    // Create application frame and pass the customer bean to operate on
    CustomerForm appFrame = new CustomerForm(bean);
    appFrame.pack();
    appFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    appFrame.setLocationRelativeTo(null);
    appFrame.setVisible(true);
  }

}
